package com.hong.day05;

import com.hong.day04.Holiday;
import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: csh
 * @Date: 2019/11/25 17:52
 * @Description:测试排他网关的存在的意义
 * 1.测试没有网关时的情况
 */
public class ExclusiveGateWayTest01 {


    //填写请假单的任务要执行完成
    public static void main(String[] args) {
        //1.得到ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //2.得到taskService
        TaskService taskService = processEngine.getTaskService();
        //3.查询当前用户的任务
        Task task = taskService.createTaskQuery()
                .processDefinitionKey("myProcess_1")
                .taskAssignee("lishi")
                .singleResult();

        //4.处理任务，结合当前用户列表的查询操作的话，任务ID5002
        if(task!=null){
            taskService.complete(task.getId());
            System.out.println("用户任务执行完毕！");
        }


        //5.输出任务的id
        System.out.println(task.getId());
    }

    public static void main2(String[] args) {
        //1.得到ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //2.得到RunService对象
        RuntimeService runtimeService = processEngine.getRuntimeService();
        Holiday holiday = new Holiday();
        holiday.setNum(5F);
        Map<String,Object> map =new HashMap <String, Object>();
        map.put("holiday",holiday);

        //3.创建流程实例 流程定义的key需要知道
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess_1",map);
        //4.输出实例的相关信息
        System.out.println("流程部署ID"+processInstance.getDeploymentId());
        System.out.println("流程实例ID"+processInstance.getId());
        System.out.println("活动ID"+processInstance.getActivityId());
    }

    public static void main1(String[] args) {
        //1.创建processEngine对象
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        //2.得到RepositoryService
        RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();
        //3.进行部署
        Deployment deployment = repositoryService.createDeployment()
                .addClasspathResource("diagram/holiday4.bpmn")
                .addClasspathResource("diagram/holiday4.png")
                .name("请假申请单流程")
                .deploy();
        //4.输出部署的一些信息
        System.out.println(deployment.getName());
        System.out.println(deployment.getId());
    }
}
